package com.ibangnuo.manage;

import com.ibangnuo.framework.domain.AdminEntity;
import com.ibangnuo.framework.utils.MD5Utils;
import com.ibangnuo.manage.dao.AdminEntityMapper;
import com.ibangnuo.manage.service.order.OrderCountService;
import com.ibangnuo.manage.service.order.OrderService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import sun.security.util.Length;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @Author: wwy
 * @Date: 2019-12-18 18:41
 */
@SpringBootTest
@RunWith(SpringRunner.class)
public class test1 {
    @Autowired
    private OrderCountService orderCountService;
    @Autowired
    private OrderService orderService;


   static Scanner scan = new Scanner(System.in);

  /*  @Test
    public  void test9() {
        System.out.println("请输入一个二进制串：");
        String s = scan.nextLine().trim();
        System.out.println(strToDou(s));

    }

        //把整数部分转成double
        public static int sToInt(String s) {
            if (s.length() == 1) return s.charAt(0) - '0';
            return sToInt(s.substring(0, s.length() - 1)) * 2
                    + (s.charAt(s.length() - 1) - '0');
        }


        //把小数部分转成double
       public static  double sToDou(String s) {
            if (s.length() == 1) return (s.charAt(0) - '0') / 2.0;
            return (s.charAt(0) - '0') / 2.0 + sToDou(s.substring(1)) / 2.0;
        }

    //把输入的字符串分成整数部分s1和小数部分s2
      public static double strToDou(String s) {
            int n = s.indexOf(".");
            if (n < 0) {
                s += ".0";
                n = s.indexOf(".");
            }
            String s1 = s.substring(0, n);
            String s2 = s.substring(n + 1);
            return sToInt(s1) + sToDou(s2);
        }
*/

    //获取上个月
    @Test
    public void test0() throws ParseException {

        String s2 = "2020-02-03";
        Date date2 = new SimpleDateFormat("yyyy-MM").parse(s2);
        Calendar calendar = new GregorianCalendar();

        calendar.setTime(date2);
        calendar.add(calendar.DATE, 0);
        SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM");
        String lastMonth = simple.format(calendar.getTime());//上个月
        System.out.println(lastMonth);
    }

    //获取当前时间的昨天
    @Test
    public void test4() {
        SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c = Calendar.getInstance();
        c.add(Calendar.DATE, -1);//-1.昨天时间 0.当前时间 1.明天时间 *以此类推
        String time = simple.format(c.getTime());
        System.out.println("昨天的时间时间是：" + time);//20190704
    }


    @Test
    public void test2() {

//        orderService.TerminalCount();//机具汇总
//        orderService.ShopCount();//门店汇总
//        orderService.CommercialCount();//商户汇总
//        orderService.CountAgent();//代理商汇总
//        orderService.CommercialCountMonth();//商户的月汇总
        orderService.AgentCountMonth();//代理商月汇总
    }

    @Test
    public void test3() {
        String firstDay, lastDay;
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        //获取前月的第一天
        Calendar cal_1 = Calendar.getInstance();//获取当前日期
        cal_1.add(Calendar.MONTH, -1);
        cal_1.set(Calendar.DAY_OF_MONTH, 1);//设置为1号,当前日期既为本月第一天
        firstDay = format.format(cal_1.getTime()) + " 00:00:00";
        System.out.println("-----1------firstDay:" + firstDay);
        //获取前月的最后一天
        Calendar cale = Calendar.getInstance();
        cale.set(Calendar.DAY_OF_MONTH, 0);//设置为1号,当前日期既为本月第一天
        lastDay = format.format(cale.getTime()) + " 23:59:59";
        System.out.println("-----2------lastDay:" + lastDay);
    }

    @Test
//    java获取当前的ip
    public void test7() {
        String cmdStr = "ipconfig";
        Runtime run = Runtime.getRuntime();
        try {
            Process process = run.exec(cmdStr);
            InputStream in = process.getInputStream();
            InputStreamReader reader = new InputStreamReader(in, "gbk");
            BufferedReader br = new BufferedReader(reader);
            StringBuffer sb = new StringBuffer();
            String message;

            while ((message = br.readLine()) != null) {
                sb.append(message);
            }
            System.out.println(sb);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

}

